package com.learning.javaweb_servlet_jdbc;

import java.sql.*;





public class JDBC_Teacher_ResultSet {
    //设置基础数据，链接数据库
    static final String URL = "jdbc:mysql://localhost:3306/jdbc_demo?useSSL=false&serverTimezone=GMT&characterEncoding=UTF-8";
    static final String USER = "root";
    static final String PASSWORD = "WQ9ABCAT";

    //查找语句
    static final String SQL = "SELECT * FROM teacher WHERE id != ?";


    public static void main(String[] args) {

        // 加载mysql驱动
        try (Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);
             // 创建Statement对象，指定结果集类型 ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY。
             PreparedStatement ps = conn.prepareStatement(SQL, java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);
        ) {
            // 设置参数
            ps.setInt(1, 0);
            // 执行查询
            try (java.sql.ResultSet rs = ps.executeQuery()) {

                // 移动到倒数第二行
                rs.absolute(-2);
                //输出倒数第二行数据
                System.out.println(rs.getObject(1) + " " + rs.getObject(2)+" " + rs.getObject(3));

            }catch (SQLException e) {
                e.printStackTrace();
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}